#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxp=10, maxsize=1024, mods=19921107;

bool checkSelf(int x, int p) {
  if (p>1) {
    for (int i=1; i<=p; i++) {
      if (((x>>(i-1))&1) && ((x>>(i%p))&1)) {
	return false;
      }
    }
  }
  return true;
}

bool checkBoth(int x, int y, int p) {
  for (int i=1; i<=p; i++) {
    if (((x>>(i-1))&1) && ((y>>(i-1))&1)) {
      return false;
    }
  }
  return true;
}

class Matrix {
public:
  int n, m;
  long long v[maxsize+1][maxsize+1];

  void initOne(int x) {
    memset(v, 0, sizeof v);
    n = m = x;
    for (int i=1; i<=x; i++) {
      v[i][i] = 1;
    }
  }

  void mul(Matrix &a, Matrix &b) {
    n = a.n, m = b.m;
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=m; j++) {
	v[i][j] = 0;
	for (int k=1; k<=a.m; k++) {
	  v[i][j] = (v[i][j]+a.v[i][k]*b.v[k][j]%mods)%mods;
	}
      }
    }
  }

  void power(long long x) {
    static Matrix s[2], t[2];
    t[1] = *this;
    s[1].initOne(n);
    int i=1, j=1;
    for (; x>1; x/=2) {
      if (x%2) {
	s[!j].mul(s[j], t[i]);
	j = !j;
      }
      t[!i].mul(t[i], t[i]);
      i = !i;
    }
    mul(t[i], s[j]);
  }
};

void buildMatrix(int p, int map[], Matrix &a) {
  a.n = a.m = map[0];
  for (int i=1; i<=map[0]; i++) {
    for (int j=1; j<=map[0]; j++) {
      a.v[i][j] = checkBoth(map[i], map[j], p);
    }
  }
}

void initMap(int p, int map[]) {
  map[0] = 0;
  for (int i=0; i<(1<<p); i++) {
    if (checkSelf(i, p)) {
      map[++map[0]] = i;
    }
  }
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  int p;
  long long q;
  scanf("%d %lld", &p, &q);

  if (p==1 && q==1) {
    printf("2\n");
  } else if (q==1) {
    int t=q;
    q=p, p=t;
  }

  static int map[maxsize+1];
  initMap(p, map);

  static Matrix trans;
  buildMatrix(p, map, trans);
  trans.power(q-1);

  long long ans=0;
  for (int i=1; i<=map[0]; i++) {
    for (int j=1; j<=map[0]; j++) {
      ans = (ans+checkBoth(map[j], map[i], p)*trans.v[i][j])%mods;
    }
  }
  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
